package ch.bfh.abcmmh.view.detailview.controllers;

import java.util.Observable;
import java.util.Observer;

import ch.bfh.abcmmh.controller.operating.LogicController;
import ch.bfh.abcmmh.controller.operating.clock.Clock;
import ch.bfh.abcmmh.view.detailview.gcarfactory.GCarFactory;
import ch.bfh.abcmmh.view.detailview.streets.StreetPanel;

public class Streetcontroller extends Observable implements Observer {
	private StreetPanel streetPanel;
	private Clock clock;
	public GCarFactory gCarfactory;
	private int currentPos;

	public Streetcontroller(StreetPanel streetPanel,
			LogicController logicController) {
		this.streetPanel = streetPanel;
		this.clock = logicController.getClock();
		this.gCarfactory = new GCarFactory(logicController.getClock(),
				streetPanel);
		logicController.getVehiclePool().addObserver(gCarfactory);
		// clock.addObserver(gCarfactory);
		clock.addObserver(this);
		this.currentPos = streetPanel.getGUIController().getDetailPosition();

	}

	public void update(Observable o, Object arg) {
		positionChanged();
		

	}

	public void positionChanged() {
		this.setChanged();
		this.notifyObservers();
		if (currentPos != gCarfactory.getStreetPanel().getGUIController()
				.getDetailPosition()) {
			currentPos = gCarfactory.getStreetPanel().getGUIController()
					.getDetailPosition();

		}
		this.clearChanged();
		streetPanel.repaintSubsandMe();
	}

	public int getCurrentPos() {
		return currentPos;
	}
}
